package com.hualan.sfzy.service.mindanswer.serviceimpl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.mindanswer.Reply;
import com.hualan.sfzy.mapper.mindanswer.ReplyMapper;
import com.hualan.sfzy.service.mindanswer.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("replyService")
public class ReplyServiceImpl implements ReplyService {
    @Autowired
    private ReplyMapper mapper;

    public  int add(Reply reply){
        Date date=new Date();
        reply.setReplyTime(date);
        return mapper.insert(reply);
    }
    public int remove(Integer id){
        return mapper.delete(id);
    }
    public int removeBatch(Integer[] ids){
        return mapper.deleteBatch(ids);
    }
    public int edit(Reply reply){
        return mapper.update(reply);
    }
    public Reply findById(Integer id){
        return mapper.selectById(id);
    }
    public List<Reply> find(){
        return mapper.select(null);
    }

    public Map<String,Object> findByPage(Integer pageNum, Integer pageSize, Reply reply){
        System.out.println(pageNum+" "+pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<Reply> list = mapper.select(reply);
        PageInfo<Reply> pageInfo = new PageInfo<>(list);
        Map<String , Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;

    }
}
